# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtk3
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.22.30
pkgrel=1
pkgdesc="GObject-based multi-platform GUI toolkit (v3) (mingw-w64)"
arch=('any')
url="https://www.gtk.org/"
license=("LGPL")
install=gtk3-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
makedepends+=("autoconf" "automake" "libtool")
# autotools are required because several Makefile.am are modified
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-atk"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libepoxy"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
options=('strip' '!debug' 'staticlibs')
source=("https://download.gnome.org/sources/gtk+/${pkgver%.*}/gtk+-${pkgver}.tar.xz"
        "0001-gtkwindow-Don-t-force-enable-CSD-under-Windows.patch")
sha256sums=('a1a4a5c12703d4e1ccda28333b87ff462741dc365131fbc94c218ae81d9a6567'
            'f6f8019e21b2932ee2cfb3b261d57b79f6492d4f0a61f9fbf5b8edd193758d9a')

prepare() {
  cd "${srcdir}/gtk+-${pkgver}"

  # https://bugzilla.gnome.org/show_bug.cgi?id=778791
  patch -p1 -i "${srcdir}"/0001-gtkwindow-Don-t-force-enable-CSD-under-Windows.patch

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  #export GI_SCANNER_DEBUG="save-temps"
  export MSYS2_ARG_CONV_EXCL="-//OASIS//DTD"
  rm -rf build-${MINGW_CHOST}
  cp -rf gtk+-${pkgver} build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/share/pkgconfig" \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-win32-backend \
    --enable-shared \
    --enable-introspection \
    --enable-broadway-backend \
    --disable-cups \
    --with-included-immodules \
    --enable-silent-rules

  make #V=1
}

package() {
  #export MSYS2_ARG_CONV_EXCL="-//OASIS"
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' -o -name '*.manifest' | xargs -rtl1 rm

  mv ${pkgdir}${MINGW_PREFIX}/bin/gtk-update-icon-cache{,-3.0}.exe
  mv ${pkgdir}${MINGW_PREFIX}/share/man/man1/gtk-update-icon-cache{,-3.0}.1

  install -Dm644 "${srcdir}/gtk+-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
